import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from "../views/home/Home"
import Test from "../views/test/Test"
import Echarts from "../views/echarts/Echarts"

// const Home = () => import('../views/home/Home')
const Cart = () => import('../views/cart/Cart')
const Category = () => import('../views/category/Category')
const Detail = () => import('../views/detail/Detail')

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/test',
    name: 'Test',
    component: Test
  },
  {
    path: '/wutai',
    name: 'Wutai',
    component: () => import('../views/wutai/wutai')
  },
  {
    path: '/echarts',
    name: 'Echarts',
    component: Echarts
  },
  {
    path: '/home',
    name: 'Home',
    component: Home
  },
  {
    path: '/detail/:id',
    name: 'detail',
    component: Detail
  },
  {
    path: '/profile',
    name: 'Profile',
    component: () => import('../views/profile/Profile')
  },
  {
    path: '/cart',
    name: 'Cart',
    component: Cart
  },
  {
    path: '/category',
    name: 'Category',
    component: Category
  },
]



const router = new VueRouter({
  // mode: 'history',
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to,from,next)=>{
  // console.log(to);
  // console.log(from);
  
  if(to.path === '/cart' ){
    next('/home')
  }
  next()
})

export default router
